Skip to content

grep: allow repeat operators with nothing to repeat after ( or | - #256

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-ere-repeat-at-start-of-subexpression
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-ere-repeat-at-start-of-subexpression

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

In -E mode, GNU grep accepts *, +, ? or {m,n} with nothing to repeat anywhere an expression starts (at index 0, or immediately following an unescaped ( or |), warns <op> at start of expression, and treats the operator as matching the empty string.

This generalizes the leading repeat operator stripping logic into normalize_ere_repeat_operators:

  • Identifies unescaped (, |, and index 0 as start of expression.
  • Strips any repeat operator (*, +, ?, or {m,n}) appearing at the start of expression while emitting warning: <op> at start of expression.
  • Handles multiple consecutive repeat operators at start of expression (e.g. **a, b|**a).
  • Ignores escaped operators (\*, \(), bracket expressions ([*]), and literal {} blocks.

Fixes #164

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.95960% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.15%. Comparing base (bf6f25e) to head (4f929ef).

Files with missing lines Patch % Lines
src/matcher.rs 95.95% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #256      +/-   ##
==========================================
- Coverage   97.22%   97.15%   -0.08%     
==========================================
  Files           6        6              
  Lines        2270     2354      +84     
  Branches      245      255      +10     
==========================================
+ Hits         2207     2287      +80     
- Misses         63       67       +4     
Flag Coverage Δ
macOS_latest 98.02% <95.95%> (-0.11%) ⬇️
ubuntu_latest 98.02% <95.95%> (-0.11%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-ere-repeat-at-start-of-subexpression (4f929ef) with main (bf6f25e)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

In -E mode, GNU grep accepts *, +, ? or {m,n} with nothing to repeat
anywhere an expression starts (at index 0, or after ( or |), warns
"<op> at start of expression", and treats the operator as matching the
empty string.

Generalize leading repeat operator stripping to normalize repeat
operators appearing at the start of any subexpression or alternative,
including doubled operators (e.g. **a, b|**a).

Fixes uutils#164

Signed-off-by: Yunus Arda Güney <yunusarda-sudo@users.noreply.github.com>
@yunusarda-sudo
yunusarda-sudo force-pushed the grep-ere-repeat-at-start-of-subexpression branch from 784bd7a to 4f929ef Compare November 25, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep - -E rejects a repeat operator with nothing to repeat after ( or |

1 participant